<!doctype html>
<html>
    <head>
        <title>{#NAV_SAVE}</title>
        {#HTML_HEADER}
    </head>
    <body>
        {#HTML_NAV}
        <div id="wrapper">
            <div id="content">
                <div id="html" class="mt-3 mb-3">{#SAVE_SETTINGS}</div>
            </div>
        </div>
        {#HTML_FOOTER}
        <script type="text/javascript">
            var intervalId = null;

            function parseGeneric(obj) {
                parseNav(obj);
                parseESP(obj);
                parseRssi(obj);
            }

            function parseHtml(obj) {
                var html = "";
                if(!obj.pending) {
                    if(intervalId != null) {
                        clearInterval(intervalId);
                    }
                    if(obj.success) {
                        var meta = document.createElement('meta');
                        meta.httpEquiv = "refresh"
                        if(!obj.reboot) {
                            html = "{#SUCCESS_SAVED_RELOAD}";
                            meta.content = "2; URL=/setup"
                        } else {
                            html = "{#SUCCESS_SAVED_REBOOT} " + obj.reload + " {#SECONDS}.";
                            meta.content = obj.reload + "; URL=/"
                        }
                        document.getElementsByTagName('head')[0].appendChild(meta);
                    } else {
                        html = "{#FAILED_SAVE}.";
                    }
                }
                document.getElementById("html").innerHTML = html;
            }

            function parse(obj) {
                if(null != obj) {
                    parseGeneric(obj["generic"]);
                    parseHtml(obj);
                }
            }

            intervalId =  window.setInterval("getAjax('/api/html/save', parse)", 2500);
            getAjax("/api/generic", parseGeneric);
        </script>
    </body>
</html>
